<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="org.xiaom.butler.bean.*" %>
<%@ page import="org.xiaom.butler.bean.area.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.form.js"></script>
<title>添加酒店</title>
</head>
<body >
	<div>
		<a href="../index.jsp">首页</a>-><a href="./list.jsp">酒店管理</a>-><a>添加</a>
	</div>
	<form id="f0" action="./add.do" accept-charset="utf-8">
		<input id="path" name="image_path" value="" type="hidden"/>
		<table>
			<tr><div><img id="img" alt="" src="http://www.baidu.com/img/bdlogo.gif"></div></tr>
			<tr>
				<td>酒店名称</td>
				<td><input name="name" type="text" value="1" maxlength="15"></td>
			</tr>
			<tr>
				<td>城市代码</td>
				<td>
					<select id="province" onchange="loadCity()">
						<option>请选择</option>
					<%
						Country country=(Country)request.getAttribute("country");
						if(country!=null){
							for(int i=0;i<country.province.length;i++){
					%>
								<option value="<%= country.province[i].id%>"><%= country.province[i].name%></option>	
					<%
							}
						}
					%>
					</select>
					<select id="city" onchange="loadCounty()">
						<option>请选择</option>
					</select>
					<select id="county" name="city_number">
						<option>请选择</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>座机号码</td>
				<td><input name="phone" type="text" value="" maxlength="255"></td>
			</tr>
			<tr>
		</table>	
	</form> 
	<table>
			<form id="f1" action="../file/upload.do" enctype="multipart/form-data" method="post">
				<tr>
					<td>app首页图片</td>
					<td><input name="image_path" type="file" value="" maxlength="255"></td>
				</tr>
				<tr>
					<td><button type="button" onclick="upload()">上传</button></td>
					<td><label id="l">asdf</label></td>
				</tr>
			</form>
			</tr>
			<tr>
				<td><button onclick="submit()">提交</button></td><td><button onclick="reset()">重置</button></td>		
			</tr>
	</table>
</body>
<script type="text/javascript">
function loadCity(){
	var id=$("#province option:selected").attr("value");
	$.getJSON("city.jsp",{province:id},function(json){
		var i;
		var str="<option>请选择</option>";
		for(i=0;i<json.length;i++){
			str+="<option value='"+json[i].id+"'>"+json[i].name+"</option>";
		}
		$("#city").html(str);
	});
}
function loadCounty(){
	var id=$("#city option:selected").attr("value");
	$.getJSON("county.jsp",{city:id},function(json){
		var str="<option>请选择</option>";
		var i;
		for(i=0;i<json.length;i++){
			str+="<option value='"+json[i].weatherCode+"'>"+json[i].name+"</option>";
		}
		$("#county").html(str);
	});
}
function upload(){ 
	 $("#f1").ajaxSubmit(function(data){
		 var json=eval("("+data+")");//转换为json对象  
		 if(json.state=="failed"){
			 alert("图片上传失败！一下是几个可能的原因：\n1，文件名非法，仅限JPG、PNG等图片格式，别手抖。"
					 +"\n2,服务器空间已满。");
		 }else{
			 $("#img").attr("src",json.path);
			 $("#path").attr("value",json.beanPath);
			 $("#l").html(json.beanPath);
		 }
     });
}
function submit(){
	$("#f0").submit();
}
function reset(){
	document.getElementById("f0").reset();
}
</script>
</html>